const app = getApp();
Page({
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    selectedCity:app.globalData.selectedCity,
    nowCity:"",
    iconList: [{
      icon: 'cardboardfill',
      color: 'red',
      badge: 120,
      name: '学科'
    }, {
      icon: 'recordfill',
      color: 'orange',
      badge: 1,
      name: '学期'
    }, {
      icon: 'picfill',
      color: 'yellow',
      badge: 0,
      name: '班次'
    }],
    gridCol: 4,
    courseData:[
      {
        name:"寒假小班西安数学培训班（七大能力）",
        startTime:"一期下午15：30-17：00",
        timeSpan:"2020-01-16 至 2020-01-22",
        addr:"雁塔西路教学点",
        mode:"0",
        teacher:"李现",
        cost:"￥1151",
        teacherImg:"https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg"
      },
      {
        name: "寒假小班西安英文培训班（七大能力）",
        startTime: "一期下午15：30-17：00",
        timeSpan: "2020-01-16 至 2020-01-22",
        addr: "雁塔东路教学点",
        mode: "1",
        teacher: "杨幂",
        cost: "￥2151",
        teacherImg: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg"
      },
      {
        name: "寒假小班西安历史培训班（七大能力）",
        startTime: "一期下午15：30-17：00",
        timeSpan: "2020-01-16 至 2020-01-22",
        addr: "雁塔东路教学点",
        mode: "0",
        teacher: "杨颖",
        cost: "￥1351",
        teacherImg: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg"
      }
    ],
    gradeArray: [
      ['幼儿园', '初中'],
      ['小班', '中班', '大班']
    ],
    gradeIndex: [0, 0],
    gradeList:[
      {
        key:"幼儿园",
        value: ['小班', '中班', '大班'],
      },
      {
        key: "初中",
        value: ['初一', '初二', '初三'],
      }
    ],
    subjectData: ['数学', '外语', '语文'],
    subjectIndex: 0,
    semesterData: ['寒假班', '暑假班', '春季班'],
    semesterIndex: 0,
    classData: ['启学', '励志', '创新'],
    classIndex: 0,
    mode1:false,
    mode2: false,
    courseTime1:false,
    courseTime2: false,
    courseTime3: false,
    courseTime4: false,
  },
  gradeChange(e) {
    this.setData({
      gradeIndex: e.detail.value
    })
  },
  gradeColumnChange(e) {
    let data = {
      gradeArray: this.data.gradeArray,
      gradeIndex: this.data.gradeIndex
    };
    let gradeList = this.data.gradeList;
    data.gradeIndex[e.detail.column] = e.detail.value;
    console.log(e)
    switch (e.detail.column) {
      case 0:
        console.log(data.gradeArray[0][e.detail.value]);
        for (let i = 0; i < gradeList.length;i++){
          if (data.gradeArray[0][e.detail.value] == gradeList[i].key){
            let classValue = gradeList[i].value;
            data.gradeArray[1] = classValue;
          }
        }
        data.gradeIndex[1] = 0;
        break;
    }
    this.setData(data);
  },
  onShow(){
    if(app.globalData.selectedCity.name !=undefined ){
      this.setData({
        nowCity: app.globalData.selectedCity.name
      })
    }else{
      this.setData({
        nowCity: "西安"
      })
    }
    // console.log(app.globalData.selectedCity.name)
  },
  courseInfo(e){
    let course = e.currentTarget.dataset.course;
    console.log(course)
    wx.navigateTo({
      url: '/pages/course/details/details'
    })
  },
  changCity(){
    wx.navigateTo({
      url: '/pages/component/city/city'
    })
  },
  changSelect(){

  },
  subjectChange(e) {
    console.log(e);
    this.setData({
      subjectIndex: e.detail.value
    })
  },
  semesterChange(e) {
    console.log(e);
    this.setData({
      semesterIndex: e.detail.value
    })
  },
  classChange(e) {
    console.log(e);
    this.setData({
      classIndex: e.detail.value
    })
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  selectSearchItem(e){
    console.log(e);
    let style = e.currentTarget.dataset.style;
    if(style =="mode1"){
      this.setData({
        mode1:!this.data.mode1
      })
    } else if (style == "mode2"){
      this.setData({
        mode2: !this.data.mode2
      })
    } else if (style == "courseTime1") {
      this.setData({
        courseTime1: !this.data.courseTime1
      })
    } else if (style == "courseTime2") {
      this.setData({
        courseTime2: !this.data.courseTime2
      })
    } else if (style == "courseTime3") {
      this.setData({
        courseTime3: !this.data.courseTime3
      })
    } else if (style == "courseTime4") {
      this.setData({
        courseTime4: !this.data.courseTime4
      })
    }
  }
})